package cz.muni.fi.pa165.musiclibrary.impl.database.entity;

import java.io.Serializable;

import javax.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;


/**
 * Implementation of genre
 * 
 * @author Martin Majlath
 * @date 2012-10-11T20:21:15+0200
 */
@Entity
@Table(name="genre")
public class Genre implements Serializable, cz.muni.fi.pa165.musiclibrary.impl.database.entity.IGenre {
    private static final long serialVersionUID = 1L;       
   
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="id_genre")
    private Long id_genre;

    @Column(nullable=false)
    private String name;
    
    @Override
    public Long getIdGenre() {
        return this.id_genre;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public void setIdGenre(@Nullable final Long idGenre) {
        id_genre = idGenre;
    }

    @Override
    public void setName(String name) {
        Validate.isTrue(name != null, "Genre's name should not be null.");
        this.name = name;
    }

    @Override
    public int hashCode() {
        return id_genre.hashCode();
    }

    @Override
    public boolean equals(Object object) {
        if (object instanceof IGenre){
            return ( ((IGenre)object).getIdGenre() == this.id_genre  );
        } else {
            return false;
        }
    }
   
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }
}
